package io.github.cubelitblade.librarymanagementbackend.utils;

import io.github.cubelitblade.librarymanagementbackend.exception.BusinessException;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(BusinessException.class)
    public ResponseEntity<ResultContext<?>> handleBusinessException(BusinessException e) {
        return ResponseEntity
                .status(e.getStatus().getHttpStatusCode())
                .body(ResultContext.failed(e.getStatus(), e.getMessage()));
    }
}
